
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "DText.h"


DText::DText(void)
{
	m_font = new wxFont(wxSize(7, 14), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
	//ZeroMemory(this, sizeof(DText));
}


DText::~DText(void)
{
	delete m_font;
	//delete [] m_name;
}

void DText::SetName(const wchar_t *str)
{
	//unsigned int len = lstrlen(&str);
	//this->m_name = new WCHAR[len];
	wcscpy(m_name, str);
}

void DText::SetPosition(wxPoint *pos)
{
	this->m_position = *pos;
}

wxPoint DText::GetPosition() const
{
	wxPoint wxp = this->m_position;
	return wxp;
}

void DText::GetText(WCHAR *str)
{
	wcscpy(str, this->m_name);
}

void DText::Draw(wxDC *dc)
{
	if(m_selected == TRUE)
	{
		dc->SetBrush(wxBrush(wxColour(0, 0, 0), wxTRANSPARENT));
		dc->SetTextForeground(wxColor(0, 0, 255));
		dc->SetFont(*m_font);
		dc->DrawText(wxString(this->m_name), this->m_position.x, this->m_position.y);

		// draw bounding box
		/*int width = m_font->GetPixelSize().x * lstrlen(m_name);// +  1 * lstrlen(m_name);
		int height = m_font->GetPixelSize().y;
		wxRect rct(m_position.x, m_position.y, width, height);
		this->DrawBoundingBox(dc, &rct);*/
	}

	else
	{
		dc->SetBrush(wxBrush(wxColour(0, 0, 0), wxTRANSPARENT));
		dc->SetTextForeground(wxColor(0, 0, 0));
		dc->SetFont(*m_font);
		dc->DrawText(wxString(this->m_name), this->m_position.x, this->m_position.y);
	}
}

bool DText::PointInside(wxPoint *pnt)
{
	int width = m_font->GetPixelSize().x * 2 * lstrlen(m_name);
	int height = m_font->GetPixelSize().y;
	wxRect rct(m_position.x, m_position.y, width, height);
	if(rct.Inside(*pnt))
		return TRUE;
	else
		return FALSE;
}

float DText::GetArea()
{
	int width = this->m_font->GetPixelSize().x;
	int height = m_font->GetPixelSize().y;
	UINT size = lstrlen(this->m_name);
	return (float)width * height * 2 * size;
}

void DText::ConvertToText(wxString *str)
{
	*str << wxT("text\t") << wxString(this->m_name) << wxT("\t") << this->m_position.x << wxT("\t") << this->m_position.y << wxT("\n");
}

wxPoint DText::GetTopLeft(void)
{
	//return this->m_position;
	return wxPoint(9999999, 9999999);
}

wxPoint DText::GetBottomRight()
{
	int width = this->m_font->GetPixelSize().x;
	int height = m_font->GetPixelSize().y;
	UINT size = lstrlen(this->m_name);
	wxPoint pnt;
	pnt.x = width * size * 2 + this->m_position.x;
	pnt.y = height + this->m_position.y;
	//return pnt;
	return wxPoint(0,0);
}